import os

def get_file_path(keyword,search_path="/Users/gdlocal/Library/Logs/Atlas"):
# def get_file_path(keyword,search_path="/Users/cyg/Library/Logs/Atlas"):
    for root, dirs, files in os.walk(search_path):
        if keyword in dirs:
            folder_path = os.path.join(root, keyword)
            print(f"找到文件夹: {folder_path}")
            return folder_path
            # break

        for file in files:
            # 检查文件名是否包含关键词并以.log结尾
            if keyword in file and file.endswith('.log'):
                full_file_path = os.path.join(root, file)
                print(f"找到文件路径: {root}")
                return root
                # break
    print("没找到")
    return "NULL"
    
def get_desktop_path():
    system = os.name  # 获取操作系统名称，'nt' 表示Windows，'posix' 表示类Unix系统，包括macOS和Linux
    
    if system == 'nt':  # Windows
        desktop = os.path.join(os.environ['USERPROFILE'], 'Desktop')
    elif system == 'posix':  # macOS 和 Linux
        desktop = os.path.join(os.path.expanduser('~'), 'Desktop')
    else:
        raise OSError("Unsupported operating system.")
    
    return desktop

if __name__ == "__main__":

    keyword = "F8YH94511ZL0000QK8"
    keyword2 = "F8YH90189EA0000ETP"
    search_path = "/Users/cyg/Library/Logs/Atlas"  # 指定搜索起始的目录
    get_file_path(keyword,search_path)
    get_file_path(keyword2,search_path)
    get_file_path("keyword2",search_path)